<?php
/**
 * Created by PhpStorm.
 * User: kaycn
 * Date: 18-9-20
 * Time: 上午1:13
 */
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require './vendor/autoload.php';

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.tom.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'liaokaycn@tom.com';                 // SMTP username
    $mail->Password = '123456Aa';                           // SMTP password
    $mail->SMTPSecure = '';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 25;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('liaokaycn@tom.com', 'Mailer');
    $mail->addAddress('liaomingzhan@hotmail.com', 'Joe User');     // Add a recipient

    $mail->AddReplyTo('2271473677@qq.com');


    //Attachments
    //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = '恭喜您注册成功， 快来体验更多功能';
    $mail->Body    = '你好廖明站 zhong过空荡荡的多充电';
    $mail->AltBody = 'This is 测试 回复邮件哦';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}